/*
 * A simple implement of a (char*)->(void*) hashtable.
 * NOTICE:
 *     The key is NOT unique and cannot be null.
 *     The value does not contain the data but only point to it.
 */

#ifndef _HASH_H_
#define _HASH_H_

#include "../../locking.h"

struct _hash_node;
struct _hash_t;

typedef void (*dumpfunc)(void *);



/*
 * The hash node
 */
typedef struct _hash_node {

    struct _hash_node *next;

    char *key;

    void *value;

} HashNode;

/*
 * The hash table
 */
typedef struct _hash_t {

    unsigned int size;

    unsigned int used;

    HashNode **ht;

    gen_lock_t *lock;

} HashTable;

HashTable *hash_create(unsigned int size);

int hash_free(HashTable *ht);

int hash_put(HashTable *ht, char *key, void *value);

void *hash_get(HashTable *ht, char *key);

int hash_remove(HashTable *ht, char *key);

void hash_dump(HashTable *ht, dumpfunc print);

void hash_print(HashTable *ht);

int hash_getSize(HashTable *theTable);

#endif
